package dao.impl;

import common.consts.Accounts;
import dao.AccountDao;
import domain.Account;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * Created by aceyin on 2015/6/8 0008.
 */
@Repository
public class AccountDaoImpl extends BaseGenericDao<Account, Long> implements AccountDao {
    @Override
    public Account findByUsername(String username) {
        Map<String, Object> params = newMapBuilder().put("username", username).build();
        return queryOne("select-user-by-username", params);
    }

    @Override
    public void updateAccountStatus(long id, Accounts.Status status) {
        Map<String, Object> params = newMapBuilder().put("id", id).put("status", status.name()).build();
        update("update-account-status", params);
    }

    @Override
    public void updateAvatar(String avatar, long id) {
        Map<String, Object> params = newMapBuilder().put("id", id).put("avatar", avatar).build();
        update("update-avatar", params);
    }

    @Override
    public void updatePassword(long id, String pwd) {
        Map<String, Object> params = newMapBuilder().put("id", id).put("password", pwd).build();
        update("update-user-password", params);
    }

    @Override
    public List<Account> findByIds(List<Long> ids) {
        Map<String, Object> params = newMapBuilder().put("ids", ids).build();
        return queryList("find-account-by-ids", params);
    }
}
